home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #40 (Jan 89) / FinderControls / Shell texte < prev   
Text File  |  1988-05-02  |  4KB  |  154 lines

  1. {**********************************************}
  2. { Put this file in the Shell Project after DAPasLib, MacTraps, ROM85lib and ROM85,}
  3. { put also CDEF text if you plan to improve and debug it. }
  4. { Don't forget to "Use resource file" "CDEF Code" in "Run options" }
  5. { of menu "Project". }
  6. { This resource file must contain the WIND ,CNTL, MENU, ICN#, ICON,}
  7. { MDEF and CDEF resource. }
  8. {**********************************************}
  9. PROGRAM shell;
  10.     USES
  11.         ROM85;
  12. {    , CDEFIcones; { only for denugging purposes }
  13.  
  14.     CONST
  15.         RestState = 0;
  16.         SelectState = 1;
  17.         OpenState = 2;
  18.         SelectOpenState = 3;
  19.         ThrownAwayState = 4;
  20.         MenuReturnState = 5;
  21.  
  22.     TYPE
  23.         CDEFcodeHdl = ^CDEFcodePtr;
  24.         CDEFcodePtr = ^CDEFcodeRecord;
  25.         CDEFcodeRecord = RECORD
  26.                 jump : integer;
  27.                 address : ProcPtr;
  28.             END;
  29.  
  30.     VAR
  31.         whichWindow, myWindow : WindowPtr;
  32.         whichControl, theTrash : ControlHandle;
  33.         myCDEF : CDEFcodeHdl;
  34.         theEvent : EventRecord;
  35.         theControl : ControlHandle;
  36.         mouse : point;
  37.         FakeRect : rect;
  38.         done : boolean;
  39.         i : integer;
  40.  
  41.     PROCEDURE ProcessMenu (where : longint);
  42.         VAR
  43.             MenuNb, ItemNb : integer;
  44.             dummy : longint;
  45.             i : integer;
  46.     BEGIN
  47.         MenuNb := HiWord(where);
  48.         ItemNb := LoWord(where);
  49.         CASE MenuNb OF
  50.             1 : 
  51.                 FOR i := 1 TO ItemNb DO
  52.                     BEGIN
  53.                         SysBeep(5);
  54.                         Delay(10, dummy);
  55.                     END;
  56.             OTHERWISE
  57.                 ;
  58.         END;
  59.     END;
  60.  
  61.  
  62.     PROCEDURE ProcessEvent;
  63.         VAR
  64.             myWindowPeek : WindowPeek;
  65.             dummy : integer;
  66.     BEGIN
  67.         CASE theEvent.what OF
  68.             UpDateEvt : 
  69.                 BEGIN
  70.                     whichWindow := WindowPtr(theEvent.message);
  71.                     beginUpDate(whichWindow);
  72.                     IF whichWindow = myWindow THEN
  73.                         BEGIN
  74.                             EraseRgn(myWindow^.VisRgn);
  75.                             UpdtControl(myWindow, myWindow^.VisRgn);
  76.                         END;
  77.                     endUpDate(whichWindow);
  78.                 END;
  79.             MouseDown : 
  80.                 BEGIN
  81.                     CASE FindWindow(theEvent.where, whichWindow) OF
  82.                         inContent : 
  83.                             BEGIN
  84.                                 mouse := theEvent.where;
  85.                                 GlobalToLocal(mouse);
  86.                                 IF FindControl(mouse, whichWindow, whichControl) <> 0 THEN
  87.                                     BEGIN
  88. { choose DragControl or TrackControl as you prefere : }
  89.  
  90. { dummy:=TrackControl(theControl,mouse,pointer(-1)) }
  91.                                         SetRect(FakeRect, 0, 0, 0, 0);
  92.                                         DragControl(whichControl, mouse, FakeRect, FakeRect, noConstraint);
  93.                                         IF GetCtlValue(whichControl) = ThrownAwayState THEN
  94.                                             BEGIN
  95.                                                 theTrash := ControlHandle(GetCRefCon(whichControl));
  96.                                                 SetCtlValue(theTrash, GetCtlValue(theTrash) - 1);
  97.                                                 DisposeControl(whichControl);
  98.                                             END
  99.                                         ELSE IF GetCtlValue(whichControl) = MenuReturnState THEN
  100.                                             BEGIN
  101.                                                 ProcessMenu(GetCRefCon(whichControl));
  102. { the Control has already been re-drawn in RestState, }
  103. { so we don't need to re-redraw it again.}
  104.                                                 whichControl^^.ContrlValue := 0;
  105.                                             END
  106.                                         ELSE IF GetCtlValue(whichControl) = SelectOpenState THEN
  107.                                             BEGIN
  108.                                                 dummy := NoteAlert(128, NIL);
  109.                                                 SetCtlValue(whichControl, RestState);
  110.                                             END
  111.                                         ELSE
  112.                                             ;
  113.                                     END;
  114.                             END;
  115.                         inGoAway : 
  116.                             IF TrackGoAway(whichWindow, theEvent.where) THEN
  117.                                 done := true;
  118.                         inDrag : 
  119.                             DragWindow(whichWindow, theEvent.where, ScreenBits.bounds);
  120.                         OTHERWISE
  121.                             ;
  122.                     END;
  123.                 END;
  124.             OTHERWISE
  125.                 ;
  126.         END;
  127.     END;
  128.  
  129. BEGIN
  130. { create a intermediate CDEF resource : }
  131. {myCDEF := CDEFcodeHdl(NewHandle(sizeof(CDEFcodeRecord)));    { for debugging only }
  132. {myCDEF^^.jump := $4EF9;                                                { for debugging only }
  133. {myCDEF^^.address := @main;                                            { for debugging only }
  134.  
  135. {AddResource(handle(myCDEF), 'CDEF', 128, '');                        { for debugging only }
  136.  
  137.     myWindow := GetNewWindow(128, NIL, pointer(-1));
  138.     SetPort(myWindow);
  139. {BackPat(gray);        { or whatever background pattern you wish }
  140.     InsertMenu(GetMenu(128), -1);
  141.     FOR i := 128 TO 133 DO
  142.         theControl := GetNewControl(i, myWindow);
  143.     done := false;
  144.     SetCursor(arrow);
  145.     FlushEvents(EveryEvent, 0);
  146.     ShowWindow(myWindow);
  147.     REPEAT
  148.         IF GetNextEvent(EveryEvent, theEvent) THEN
  149.             ProcessEvent;
  150.     UNTIL done;
  151.     DisposeWindow(myWindow);
  152. {RmveResource(handle(myCDEF));                    { for debugging only }
  153. {DisposHandle(handle(myCDEF));                    { for debugging only }
  154. END.